package com.tim.helper.inactive;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.junit.Test;

public class GroovyEngineHelper {

    /**
     * org.codehaus.groovy#groovy
     */
    @Test
    public void calculate(){
        GroovyShell groovyShell = new GroovyShell();
        Binding binding = new Binding();
        binding.setVariable("a", 13);
        binding.setVariable("b", "13");// 注意参数类型

        Script script = groovyShell.parse("a+1");
        Object obj = InvokerHelper.createScript(script.getClass(), binding).run();
        System.out.println(obj);

        script = groovyShell.parse("b+1");
        obj = InvokerHelper.createScript(script.getClass(), binding).run();
        System.out.println(obj);


    }

}
